package com.mac.intellect_flow.admin.controller.system;

import com.mac.intellect_flow.reply.R;
import com.mac.intellect_flow.sys.model.RegisterBody;
import com.mac.intellect_flow.sys.service.SysConfigService;
import com.mac.intellect_flow.sys.service.SysRegisterService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册
 * 
 * @author mac
 */
@Tag(name = "注册")
@RestController
public class SysRegisterController {
    @Autowired
    private SysRegisterService registerService;

    @Autowired
    private SysConfigService configService;

    @PostMapping("/register")
    public R register(@RequestBody RegisterBody user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return R.error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? R.success() : R.error(msg);
    }
}
